@tool
class_name AutoPivotContainer
extends Container

## 根据类型自动设置Pivot百分比位置的容器

## 锚点类型
enum PivotType
{
	TOP,
	LEFT,
	RIGHT,
	BOTTOM,
	CENTER,
	TOP_LEFT,
	TOP_RIGHT,
	BOTTOM_LEFT,
	BOTTOM_RIGHT,
	CUSTOM,
}

@export var pivot_type:PivotType = PivotType.CENTER:
	set(value):
		pivot_type = value
		_on_size_or_type_changed()
var connect_obj:ConnectObj

func _on_size_or_type_changed():
	match pivot_type:
		PivotType.TOP:
			pivot_offset = Vector2(size.x/2,0)
		PivotType.LEFT:
			pivot_offset = Vector2(0,size.y/2)
		PivotType.RIGHT:
			pivot_offset = Vector2(size.x,size.y/2)
		PivotType.BOTTOM:
			pivot_offset = Vector2(size.x/2,size.y)
		PivotType.CENTER:
			pivot_offset = Vector2(size.x/2,size.y/2)
		PivotType.TOP_LEFT:
			pivot_offset = Vector2(0,0)
		PivotType.TOP_RIGHT:
			pivot_offset = Vector2(size.x,0)
		PivotType.BOTTOM_LEFT:
			pivot_offset = Vector2(0,size.y)
		PivotType.BOTTOM_RIGHT:
			pivot_offset = Vector2(size.x,size.y)
		PivotType.CUSTOM:
			pass
func _enter_tree() -> void:
	_on_size_or_type_changed()
	connect_obj = ConnectObj.new(resized,[_on_size_or_type_changed])
func _notification(what: int) -> void:
	if what == NOTIFICATION_PREDELETE:
		if connect_obj:
			connect_obj.disconnect_all()
